//
//  SportSkillViewController.m
//  CoolTennisBall
//
//  Created by 谢伟康 on 15/12/18.
//  Copyright © 2015年 CoolLang. All rights reserved.
//

#import "SportSkillViewController.h"
#import "CoollangTennisBall-Swift.h"
#import "CircleChartView.h"
#import "PNChart.h"
#import "SportDetailReportModel.h"
#import "NSBundle+CurrentLanguage.h"
#import <UICountingLabel/UICountingLabel.h>
#import "NewCurveLineChartView.h"

static const CGFloat kForeBackHandMargin = 15.0f;       // 约束左右间距

typedef NS_ENUM(NSUInteger, ValueType) {
    ValueTypeMax,       // 最大值
    ValueTypeAverage    // 平均值
};

@interface SportSkillViewController ()
@property (weak, nonatomic) IBOutlet CircleChartView *circleView;
@property (weak, nonatomic) IBOutlet UIView *circelSuperView;

@property (weak, nonatomic) IBOutlet UIView *shootBgView;
@property (weak, nonatomic) IBOutlet UIView *speedBgView;
@property (weak, nonatomic) IBOutlet UIView *sportStrongerBgView;
@property (strong, nonatomic) PNCircleChart *pnShootCirCleView;
@property (strong, nonatomic) PNCircleChart *pnSpeedCirCleView;
@property (strong, nonatomic) PNCircleChart *pnSportStrongerCirCleView;
@property (weak, nonatomic) IBOutlet UIView *lineChartView;
@property (weak, nonatomic) IBOutlet NewCurveLineChartView *newlineChartView;
@property (weak, nonatomic) IBOutlet UILabel *sportStyleLabel;
@property (weak, nonatomic) IBOutlet UILabel *sportDescribeLabel;

@property (weak, nonatomic) IBOutlet UILabel *skillDescriptionLabel;
@property (weak, nonatomic) IBOutlet UILabel *serveDescriptionLabel;
@property (weak, nonatomic) IBOutlet UILabel *smashDescriptionLabel;
@property (weak, nonatomic) IBOutlet UILabel *volleyDescriptionLabel;
@property (weak, nonatomic) IBOutlet UILabel *sliceDescriptionLabel;
@property (weak, nonatomic) IBOutlet UILabel *topspinDescriptionLabel;
@property (weak, nonatomic) IBOutlet UILabel *flatDescriptionLabel;

@property (weak, nonatomic) IBOutlet UILabel *powerDescriptionLabel;
@property (weak, nonatomic) IBOutlet UILabel *enduranceDescriptionLabel;
@property (weak, nonatomic) IBOutlet UILabel *intensityDescriptionLabel;
@property (weak, nonatomic) IBOutlet DesignableButton *powerScoreDescriptionButton;
@property (weak, nonatomic) IBOutlet DesignableButton *enduranceScoreDescriptionButton;
@property (weak, nonatomic) IBOutlet DesignableButton *intensityScoreDescriptionButton;

@property (weak, nonatomic) IBOutlet UILabel *resistanceCurveDescriptionLabel;
@property (weak, nonatomic) IBOutlet UILabel *averageSpeedLabel;
@property (weak, nonatomic) IBOutlet UILabel *sportDurationLabel;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *handTypeMarginConstraint;  // 左右手间隔右方约束

@property (weak, nonatomic) IBOutlet UICountingLabel *forehandTopspinCountLabel; // 正手上旋
@property (weak, nonatomic) IBOutlet UICountingLabel *forehandFlatCountLabel;   // 正手平击
@property (weak, nonatomic) IBOutlet UICountingLabel *forehandSliceCountLabel;  // 正手削球
@property (weak, nonatomic) IBOutlet UICountingLabel *backhandTopspinCountLabel;
@property (weak, nonatomic) IBOutlet UICountingLabel *backhandFlatCountLabel;
@property (weak, nonatomic) IBOutlet UICountingLabel *backhandSliceCountLabel;
@property (weak, nonatomic) IBOutlet UICountingLabel *serveCountLabel;

@property (weak, nonatomic) IBOutlet UISegmentedControl *speedSegmentedControl;
@property (weak, nonatomic) IBOutlet UILabel *forehandSpeedDescriptionLabel;
@property (weak, nonatomic) IBOutlet UILabel *backhandSpeedDescriptionLabel;

@property (weak, nonatomic) IBOutlet UILabel *topspinSpeedDescriptionLabel;
@property (weak, nonatomic) IBOutlet UILabel *flatSpeedDescriptionLabel;
@property (weak, nonatomic) IBOutlet UILabel *sliceSpeedDescriptionLabel;
@property (weak, nonatomic) IBOutlet UILabel *serveSpeedDescriptionLabel;
@property (weak, nonatomic) IBOutlet UILabel *forehandDescriptionLabel;
@property (weak, nonatomic) IBOutlet UILabel *backhandDescriptionLabel;
@property (weak, nonatomic) IBOutlet UILabel *forehandPercentLabel;
@property (weak, nonatomic) IBOutlet UILabel *backhandPercentLabel;
@property (weak, nonatomic) IBOutlet UILabel *swingSpeedLab;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *leftMarginCon;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *rightMarginCon;
@end

@implementation SportSkillViewController
{
    BOOL _hasShowSportValues;   // 是否显示过动画
    BOOL isShowPlaySkills; // YES 显示击球风格， NO 显示击球数
}

#pragma mark - View LifeCycle
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self configureLocalization];
    [self configureCountingLabels];
    [self updateUI];
    isShowPlaySkills = YES;
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self updateUI];
    });
    
}

#pragma mark - Localization

- (void)configureLocalization
{
    if ([NSBundle currentLangeuage] == kLanguageFrennch && kYFScreenWidth < 375) {
        self.leftMarginCon.constant = 6;
        self.rightMarginCon.constant = 6;
        self.serveDescriptionLabel.font=[UIFont systemFontOfSize:12];
    }else if ([NSBundle currentLangeuage] == kLanguageEnglish && kYFScreenWidth < 375) {
        self.leftMarginCon.constant = 8;
        self.rightMarginCon.constant = 8;
    }
    
    self.serveDescriptionLabel.text = NSLocalizedString(@"Serve", nil);
    self.smashDescriptionLabel.text = NSLocalizedString(@"Smash", nil);
    self.volleyDescriptionLabel.text = NSLocalizedString(@"Volley", nil);
    self.sliceDescriptionLabel.text = NSLocalizedString(@"Slice", nil);
    self.topspinDescriptionLabel.text = NSLocalizedString(@"Topspin", nil);
    self.flatDescriptionLabel.text = NSLocalizedString(@"Flat", nil);
    //"Report Playing skills" = "打法风格";
//    "SportSkill.Shots" = "总击球数";
    self.skillDescriptionLabel.text = NSLocalizedString(@"Report Playing skills", nil);
    self.powerDescriptionLabel.text = NSLocalizedString(@"Explosive Power", nil);
    self.enduranceDescriptionLabel.text = NSLocalizedString(@"Endurance", nil);
    self.intensityDescriptionLabel.text = NSLocalizedString(@"Intensity", nil);
    self.resistanceCurveDescriptionLabel.text = NSLocalizedString(@"Speed Curve", nil);
    self.averageSpeedLabel.text = NSLocalizedString(@"Avg Swing Speed", nil);
    self.sportDurationLabel.text = NSLocalizedString(@"Active time", nil);
    self.sportDescribeLabel.text = NSLocalizedString(@"Statistics.CurveLineDescription", nil);
    
    if (![NSBundle currentLanguageIsChinese]) {
        self.powerDescriptionLabel.font = [UIFont boldSystemFontOfSize:10];
        self.enduranceDescriptionLabel.font = [UIFont boldSystemFontOfSize:10];
        self.intensityDescriptionLabel.font = [UIFont boldSystemFontOfSize:10];
        self.resistanceCurveDescriptionLabel.font = [UIFont boldSystemFontOfSize:14];
        self.swingSpeedLab.text = [NSBundle currentLangeuage] == kLanguageFrennch ? @"Vitesse de frappe":@"Swing Speed";
        self.swingSpeedLab.hidden = NO;
        NSMutableAttributedString *averageSpeedAtt = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"Avg Swing Speed", nil) attributes:@{NSFontAttributeName: [UIFont boldSystemFontOfSize:8]}];
        [averageSpeedAtt appendAttributedString:[[NSAttributedString alloc] initWithString:@" (km/h)" attributes:@{ NSFontAttributeName: [UIFont systemFontOfSize:8] }]];
        self.averageSpeedLabel.attributedText = averageSpeedAtt;
        
        NSMutableAttributedString *sportDurationAtt = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"Active time", nil) attributes:@{NSFontAttributeName: [UIFont boldSystemFontOfSize:8]}];
        [sportDurationAtt appendAttributedString:[[NSAttributedString alloc] initWithString:@" (min)" attributes:@{ NSFontAttributeName: [UIFont systemFontOfSize:8] }]];
        self.sportDurationLabel.attributedText = sportDurationAtt;
    }else {
        self.swingSpeedLab.hidden = YES;
    }
    
    self.topspinSpeedDescriptionLabel.text = NSLocalizedString(@"Topspin", nil);
    self.flatSpeedDescriptionLabel.text = NSLocalizedString(@"Flat", nil);
    self.sliceSpeedDescriptionLabel.text = NSLocalizedString(@"Slice", nil);
    self.serveSpeedDescriptionLabel.text = NSLocalizedString(@"Serve", nil);
    [self.speedSegmentedControl setTitle:NSLocalizedString(@"Avg", nil) forSegmentAtIndex:0];
    [self.speedSegmentedControl setTitle:NSLocalizedString(@"Max", nil) forSegmentAtIndex:1];
    self.forehandSpeedDescriptionLabel.text = NSLocalizedString(@"Forehand speed", nil);
    self.backhandSpeedDescriptionLabel.text = NSLocalizedString(@"Backhand speed", nil);
    self.forehandDescriptionLabel.text = NSLocalizedString(@"Forehand", nil);
    self.backhandDescriptionLabel.text = NSLocalizedString(@"Backhand", nil);
}

#pragma mark - IBAction

- (IBAction)showValueExplanation:(UITapGestureRecognizer *)sender {
    [self showGuideWithObjcBridge:1 currentPage:sender.view.tag - 100];
}

- (IBAction)changeValueModeShow:(UISegmentedControl *)sender {
    if (sender.selectedSegmentIndex == 0) {
        [self showValueType:ValueTypeAverage];
    } else {
        [self showValueType:ValueTypeMax];
    }
}

- (IBAction)showForeBackHandDescription:(id)sender {
    [self showGuideWithObjcBridge:4 currentPage:0];
}

/**
 *  点击圆盘中心切换风格
 */
- (IBAction)pieCoverButton:(UIButton *)sender {

    isShowPlaySkills = !isShowPlaySkills;
    if (isShowPlaySkills) {
        [self configureSportStyleLabel];
        self.skillDescriptionLabel.text = NSLocalizedString(@"Report Playing skills", nil);
        
    }else {
        self.sportStyleLabel.text = @([self.detailReportModel amountOfCount]).stringValue;
        self.skillDescriptionLabel.text = NSLocalizedString(@"SportSkill.Shots", nil);
      
    }
    [self configureCircleChartView];

}

#pragma mark - Public Method

- (void)updateUI
{
    if (_hasShowSportValues && self.detailReportModel != nil) {
        return;
    } else if (self.detailReportModel != nil) {
        _hasShowSportValues = YES;
    }
    [self.view layoutIfNeeded];
    [self configurePNCircleView];
    [self configureCircleChartView];
    [self configureLineChartView];
    [self configureSportStyleLabel];
    [self configureForeHandPercent:self.detailReportModel.forehandPercent];
    [self showValueType:ValueTypeAverage];
}

#pragma mark - Private Method

//配置爆发力及耐久力，运动强度
- (void)configurePNCircleView
{
    if (self.pnShootCirCleView != nil) {
        [self.pnShootCirCleView removeFromSuperview];
    }
    self.pnShootCirCleView = [[PNCircleChart alloc] initWithFrame:self.shootBgView.bounds total:@1 current:@(self.detailReportModel.speedPercent) clockwise:YES shadow:YES shadowColor:[UIColor colorWithHex:0xdededf alpha:1.0]];
    
    self.pnShootCirCleView.chartType = PNChartFormatTypePercent;
    self.pnShootCirCleView.strokeColor = kSelectedColor;
    self.pnShootCirCleView.lineWidth = @6;
    self.pnShootCirCleView.countingLabel.textColor = kUnSelectedColor;
    self.pnShootCirCleView.countingLabel.font = [UIFont boldSystemFontOfSize:15];
    [self.shootBgView addSubview:self.pnShootCirCleView];
    
    if (self.pnSpeedCirCleView != nil) {
        [self.pnSpeedCirCleView removeFromSuperview];
    }
    self.pnSpeedCirCleView = [[PNCircleChart alloc] initWithFrame:self.speedBgView.bounds total:@1 current:@(self.detailReportModel.durationPercent) clockwise:YES shadow:YES shadowColor:[UIColor colorWithHex:0xdededf alpha:1.0]];
    self.pnSpeedCirCleView.chartType = PNChartFormatTypePercent;
    self.pnSpeedCirCleView.strokeColor = kOrangeColor;
    self.pnSpeedCirCleView.lineWidth = @6;
    self.pnSpeedCirCleView.countingLabel.textColor = kUnSelectedColor;
    self.pnSpeedCirCleView.countingLabel.font = [UIFont boldSystemFontOfSize:15];
    [self.speedBgView addSubview:self.pnSpeedCirCleView];
    
    if (self.pnSportStrongerCirCleView != nil) {
        [self.pnSportStrongerCirCleView removeFromSuperview];
    }
    self.pnSportStrongerCirCleView = [[PNCircleChart alloc] initWithFrame:self.sportStrongerBgView.bounds total:@1 current:@(self.detailReportModel.hitPercent) clockwise:YES shadow:YES shadowColor:[UIColor colorWithHex:0xdededf alpha:1.0]];
    self.pnSportStrongerCirCleView.chartType = PNChartFormatTypePercent;
    self.pnSportStrongerCirCleView.strokeColor = [UIColor colorWithHex:0xf73f3d alpha:1.0];
    self.pnSportStrongerCirCleView.lineWidth = @6;
    self.pnSportStrongerCirCleView.countingLabel.textColor = kUnSelectedColor;
    self.pnSportStrongerCirCleView.countingLabel.font = [UIFont boldSystemFontOfSize:15];
    [self.sportStrongerBgView addSubview:self.pnSportStrongerCirCleView];
    
    [self.pnShootCirCleView strokeChart];
    [self.pnSpeedCirCleView strokeChart];
    [self.pnSportStrongerCirCleView strokeChart];
    
    [self.powerScoreDescriptionButton setTitle:[self.detailReportModel powerScoreDescription] forState:UIControlStateNormal];
    [self.enduranceScoreDescriptionButton setTitle:[self.detailReportModel enduranceScoreDescription] forState:UIControlStateNormal];
    [self.intensityScoreDescriptionButton setTitle:[self.detailReportModel intensityScoreDescription] forState:UIControlStateNormal];
}

- (void)configureSportStyleLabel
{
    if (self.detailReportModel == nil) {
        return;
    }
    
    CGFloat ratio = 0.0f;
    ratio = (CGFloat)(self.detailReportModel.jieJiCount + self.detailReportModel.kouShaCount)/(self.detailReportModel.kouShaCount + self.detailReportModel.jieJiCount + self.detailReportModel.xueQiuCount + self.detailReportModel.xuanQiuCount + self.detailReportModel.pingJiCount);
    if (ratio < 0.2) {
        self.sportStyleLabel.text = NSLocalizedString(@"baseline type", nil);
    } else if (ratio > 0.4) {
        self.sportStyleLabel.text = NSLocalizedString(@"serve & volley type", nil);
    } else {
        self.sportStyleLabel.text = NSLocalizedString(@"comprehensive type", nil);
    }
}



//配置顶部圆形
- (void)configureCircleChartView
{
    NSArray *dataArr = @[@(self.detailReportModel.faQiuCount),@(self.detailReportModel.kouShaCount),@(self.detailReportModel.jieJiCount),@(self.detailReportModel.xueQiuCount),@(self.detailReportModel.xuanQiuCount),@(self.detailReportModel.pingJiCount)];
    
    NSArray *titleArr = @[NSLocalizedString(@"Serve", nil), NSLocalizedString(@"Smash", nil), NSLocalizedString(@"Volley", nil), NSLocalizedString(@"Slice", nil),NSLocalizedString(@"Topspin", nil), NSLocalizedString(@"Flat", nil)];
    
    NSArray *colorArr = @[[UIColor colorWithHex:0x7abeea alpha:1.0],[UIColor colorWithHex:0x72deae alpha:1.0],[UIColor colorWithHex:0xf8c353 alpha:1.0],[UIColor colorWithHex:0xf88360 alpha:1.0],[UIColor colorWithHex:0xf06fa4 alpha:1.0],[UIColor colorWithHex:0xa489d6 alpha:1.0]];
    
    [self.circleView configureDataArray:dataArr titleArray:titleArr colorArray:colorArr isPresent:isShowPlaySkills];
}

- (NSArray *)calculateLineChartYDataSource
{
    NSMutableArray *dataArr = @[].mutableCopy;
    User *user = [User getLastUser];
    RLMResults *results = [user.sportRecordItems objectsWhere:@"dateTimeStamp == %lld",self.selectedDayTimeStamp];
    SportRecordItem *item = [results firstObject];
    if (item == nil) {
        return dataArr;
    }
    RLMResults * swingResults = [item.barChartItems sortedResultsUsingProperty:@"unixTimeStamp" ascending:YES];
    NSArray * barItems = (NSArray *)swingResults;
    NSInteger count = barItems.count/10;
    NSInteger speedSum = 0;
    NSInteger index = 0;
    for (BarChartItem *item in barItems) {
        speedSum += [item.maxSpeed integerValue];
        if (index%(count - 1) == 0 && index != 0) {
            NSInteger averageSpeed = speedSum/count;
            [dataArr addObject:@(averageSpeed)];
            speedSum = 0;
            if (dataArr.count == 10) {
                break;
            }
        }
        index++;
    }
    NSMutableArray * newDataArr = @[].mutableCopy;
//    if ([dataArr firstObject] != nil) {        
//        [newDataArr addObject:[dataArr firstObject]];
//    }
    [newDataArr addObjectsFromArray:dataArr];
    
    return newDataArr;
}

- (NSArray *)calculateLineChartXDataSource
{
    NSMutableArray *dataArr = @[].mutableCopy;

    NSInteger minutes = self.detailReportModel.effectiveSportTime;
    if (minutes < 10) {
        return dataArr;
    }
    NSInteger integerMinutes = (NSInteger)roundf(minutes/10.0)*10;
    for (NSInteger i = 0; i < 10; i++) {
        [dataArr addObject:[NSString stringWithFormat:@"%ld",(long)i * integerMinutes/10]];
    }
    return dataArr;
}

//配置底部曲线图
- (void)configureLineChartView
{
    NSArray * xAxisArr = [self calculateLineChartXDataSource];
    NSArray * dataArr = (xAxisArr.count == 0 )?@[]:[self calculateLineChartYDataSource];
    
    self.sportDescribeLabel.hidden = ([self calculateLineChartXDataSource].count == 0 )? NO : YES;
    
    [self.newlineChartView ConfigerTheme:kTennisBaseStyle];
    [self.newlineChartView defaultSuitableSettingCompare:0 maxValue:200 setAxis:kAxisLeft labelCount:5 show:YES drawGridLinesEnabled:YES axisLineColor:[UIColor clearColor]];
    [self.newlineChartView defaultSuitableSettingCompare:0 maxValue:200 setAxis:kAxisRight labelCount:5 show:NO drawGridLinesEnabled:NO axisLineColor:[UIColor clearColor]];
    CurveLineItem *lineItem =  [[CurveLineItem alloc] initWithLineWidth:2.0 color:kSelectedColor fullColor:[UIColor colorWithHex:0x25c9ad alpha:0.3] xValues:xAxisArr yValues:dataArr];
    [self.newlineChartView drawLineWithCurveLineItemArr:@[ lineItem] showAnimation:YES];
    if (xAxisArr.count > 0) {[self.newlineChartView configuerXAxisValus:xAxisArr];}
}

- (void)showGuideWithObjcBridge:(NSInteger)bridgeNum
                    currentPage:(NSInteger)page
{
//    if (![NSBundle currentLanguageIsChinese]) {
//        return;
//    }
    
    QuickGuidePageViewController *controller = [[QuickGuidePageViewController alloc] init];
    controller.objc_guideTypeNum = bridgeNum;
    controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    controller.modalPresentationStyle = UIModalPresentationOverFullScreen;
    controller.currentIndexPage = page;
    [self presentViewController:controller animated:YES completion:nil];
}

- (void)configureForeHandPercent:(NSInteger)foreHandPercent
{
    CGFloat amountWidth = ([UIScreen mainScreen].bounds.size.width - kForeBackHandMargin * 2);
    CGFloat foreHandWidth = amountWidth * foreHandPercent * 0.01;
    self.handTypeMarginConstraint.constant = - (amountWidth - foreHandWidth);
    [self.view layoutIfNeeded];
    
    self.forehandPercentLabel.text = [NSString stringWithFormat:@"%zd%%", foreHandPercent];
    self.backhandPercentLabel.text = [NSString stringWithFormat:@"%zd%%", 100 - foreHandPercent];
}

- (void)configureCountingLabels
{
    self.forehandTopspinCountLabel.format = @"%d";
    self.forehandFlatCountLabel.format = @"%d";
    self.forehandSliceCountLabel.format = @"%d";
    self.backhandTopspinCountLabel.format = @"%d";
    self.backhandFlatCountLabel.format = @"%d";
    self.backhandSliceCountLabel.format = @"%d";
    self.serveCountLabel.format = @"%d";
}

- (void)showValueType:(ValueType)type
{
    NSMutableArray *typeSpeeds = nil;
    
    switch (type) {
        case ValueTypeMax:
            typeSpeeds = self.detailReportModel.maxTypeSpeeds;
            break;
        case ValueTypeAverage:
            typeSpeeds = self.detailReportModel.avgTypeSpeeds;
            break;
        default:
            break;
    }
    
    if (!([typeSpeeds count] > 0)) {
        [self configureCountingLabel:self.forehandTopspinCountLabel withValue:0];
        [self configureCountingLabel:self.forehandFlatCountLabel withValue:0];
        [self configureCountingLabel:self.forehandSliceCountLabel withValue:0];
        [self configureCountingLabel:self.backhandTopspinCountLabel withValue:0];
        [self configureCountingLabel:self.backhandFlatCountLabel withValue:0];
        [self configureCountingLabel:self.backhandSliceCountLabel withValue:0];
        [self configureCountingLabel:self.serveCountLabel withValue:0];
        [self configureForeHandPercent:50];
        return;
    }
    
    if ([typeSpeeds count] > 4) {
        SportDetailSpeedItem *topsinItem = typeSpeeds[4];
        [self configureCountingLabel:self.forehandTopspinCountLabel withValue:topsinItem.forehandSpeed];
        [self configureCountingLabel:self.backhandTopspinCountLabel withValue:topsinItem.backhandSpeed];
    }
    
    if ([typeSpeeds count] > 5) {
        SportDetailSpeedItem *flatItem = typeSpeeds[5];
        [self configureCountingLabel:self.forehandFlatCountLabel withValue:flatItem.forehandSpeed];
        [self configureCountingLabel:self.backhandFlatCountLabel withValue:flatItem.backhandSpeed];
    }
    
    if ([typeSpeeds count] > 3) {
        SportDetailSpeedItem *sliceItem = typeSpeeds[3];
        [self configureCountingLabel:self.forehandSliceCountLabel withValue:sliceItem.forehandSpeed];
        [self configureCountingLabel:self.backhandSliceCountLabel withValue:sliceItem.backhandSpeed];
    }
    
    SportDetailSpeedItem *serveItem = typeSpeeds[0];
    
    [self configureCountingLabel:self.serveCountLabel withValue:serveItem.forehandSpeed];
}

- (void)configureCountingLabel:(UICountingLabel *)label withValue:(NSString *)valueStr
{
    if ([valueStr integerValue] == 0) {
        label.text = @"--";
    } else {
        label.text = valueStr;
        label.alpha = 0;
        [UIView animateWithDuration:0.35 animations:^{
            label.alpha = 1.0f;
        }];
    }
}

#pragma mark - UITableView Delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.section == 3) {
        // 显示正反手说明
        [self showGuideWithObjcBridge:2 currentPage:0];
    } else if (indexPath.section == 4) {
        // 显示运动曲线说明
        [self showGuideWithObjcBridge:3 currentPage:0];
    }
}

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 3 || indexPath.section == 4) {
        return indexPath;
    } else {
        return nil;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 1.0f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 6.0f;
}

@end
